package yartiss.engine.simulation.system.taskset;

import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

import yartiss.engine.simulation.system.ITask;
import yartiss.engine.simulation.system.ITaskSet;

public abstract class AbstractTaskSet implements ITaskSet{

	private TreeSet<ITask> tasks;
	private int id;
	
	protected final Comparator<ITask> comparator ;
	
	
	protected AbstractTaskSet(Comparator<ITask> comp){
		comparator = comp;
		this.tasks = new TreeSet<ITask>(comp);
	}
	
	@Override
	public Iterator<ITask> iterator() {
		return tasks.iterator();
	}

	@Override
	public boolean addTask(ITask t) {
		return tasks.add(t);
	}
	
	@Override
	public boolean addTasks(List<ITask> t) {
		return tasks.addAll(t);
	}

	@Override
	public int getAllTasksCount() {
		return tasks.size();
	}

	@Override
	public SortedSet<ITask> getHeadSet(ITask task, boolean inclusive) {
		SortedSet<ITask> activeTasks = new TreeSet<ITask>(comparator);
		return activeTasks;
	}

	@Override
	public int getId() {
		return id;
	}

	@Override
	public int setId(int id) {
		return this.id = id;
	}

	@Override
	public ITask getOne() {
		return tasks.first();
	}
	
	@Override
	public ITaskSet cloneTaskSet() {
		PriorityTaskSet set = new PriorityTaskSet();
		for (ITask task : tasks) {
			set.addTask(task.cloneTask());
		}
		return set;
	}


}
